package com.bcdat.bcdatbrace.bacdatKafka.server.impl;

import com.bcdat.bcdatbrace.bacdatKafka.server.KafkaServer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;
/**
 * @author lwz
 * @version 0.1
 * @date 2019/09/30 15:32
 * kafka消费者
 */
@Component
public class KafkaReceiver implements KafkaServer {

    final String ZHISHENG = "zhisheng";

    @KafkaListener(topics = {ZHISHENG})
    public void listen(ConsumerRecord<?,?> record){
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()){
            //输出打印结果
            System.out.println(kafkaMessage.get());
        }
    }
}
